home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Scope / Scope Disk #010 (199x)(Scope PD)(US)[WB].zip / Scope Disk #010 (199x)(Scope PD)(US)[WB].adf / Ixecute / ixecute.c < prev    next >
C/C++ Source or Header  |  1988-05-18  |  3KB  |  108 lines

  1. #include <string.h>
  2. #include "exec/types.h"
  3. #include "exec/memory.h"
  4. #include "workbench/workbench.h"
  5. #include "workbench/startup.h"
  6. #include "workbench/icon.h"
  7. #include "libraries/dosextens.h"
  8. extern struct WBStartup *WBenchMsg;
  9. extern struct FileHandle *Open();
  10. extern struct DiskObject *GetDiskObject();
  11. extern struct Library *OpenLibrary();
  12. LONG IconBase;
  13.  
  14. void type(string)
  15. char *string;
  16. {
  17.     Write(Output(),string,strlen(string));
  18. }
  19.  
  20. void main(argc,argv)
  21. int argc;
  22. char **argv;
  23.  
  24. {
  25.     int fileLength;
  26.     char **tools;
  27.     char *inputBuffer;
  28.     struct FileHandle *execFile, *users_Dir, *ixWindow, *tempFile=0;
  29.     struct WBArg *whoCalled;
  30.     struct DiskObject *do_ptr;
  31.  
  32.     if (argc) /* the idiot ran me from CLI! */
  33.     {
  34.     type("Usage:\n");
  35.     type("Make this program the default tool for a project-type icon.\n");
  36.     type("Make the file associated with the icon a CLI script.\n");
  37.     type("The CLI script will be executed when the icon is launched.\n");
  38.     type("\nPublic domain software by Benson the Dog.\n");    
  39.     }
  40.     else
  41.     {
  42.     whoCalled = WBenchMsg->sm_ArgList;
  43.     users_Dir = (struct FileHandle *) CurrentDir(whoCalled[1].wa_Lock);
  44.     ixWindow = Open("CON:10/10/500/150/Ixecute",MODE_OLDFILE);
  45.     execFile = Open(whoCalled[1].wa_Name,MODE_OLDFILE);
  46.     if (execFile)
  47.     {
  48.         if (!(IconBase = (LONG) OpenLibrary("icon.library",0)))
  49.         {
  50.             Write(ixWindow,"Can't open icon library.",24);
  51.             goto earlyEnd;
  52.         }
  53.         do_ptr = GetDiskObject(whoCalled[1].wa_Name);
  54.         tools = do_ptr->do_ToolTypes;
  55.         if (!(strnicmp(*tools,"expert",6)))
  56.             Write(ixWindow,"Expert\n",7);
  57.         else
  58.         {
  59.             tempFile = Open("SYS:t/Ixec.temp",MODE_NEWFILE);
  60.             if (tempFile)
  61.             {
  62.                 Seek(execFile,0,OFFSET_END);
  63.                 fileLength = Seek(execFile,0,OFFSET_BEGINNING);
  64.                 if (inputBuffer = (char *) AllocMem(fileLength,MEMF_FAST))
  65.                 {
  66.                     Read(execFile,inputBuffer,fileLength);
  67.                     Write(tempFile,"cd SYS:\n",8);
  68.                     Write(tempFile,inputBuffer,fileLength);
  69.                     Write(tempFile,"endcli\n",7);
  70.                     Close(execFile);
  71.                     Close(tempFile);
  72.                     execFile = Open("SYS:t/Ixec.temp",MODE_OLDFILE);
  73.                     FreeMem(inputBuffer,fileLength);
  74.                 }
  75.                 else
  76.                 {
  77.                     FreeDiskObject(do_ptr);
  78.                     Write(ixWindow,"Not enough memory. Use expert mode.",35);
  79.                     goto earlyEnd;
  80.                 }                
  81.             }
  82.             else
  83.             {
  84.                 FreeDiskObject(do_ptr);
  85.                 Write(ixWindow,"Can't open temp file.",21);
  86.                 goto earlyEnd;
  87.             }
  88.         }
  89.         CloseLibrary(IconBase);
  90.         FreeDiskObject(do_ptr);
  91.         Execute("",execFile,ixWindow);
  92.         Close(execFile);
  93.         if (tempFile)
  94.             DeleteFile("SYS:t/Ixec.temp");
  95.     }
  96.     else
  97.     {    
  98.         Write(ixWindow,"\n\n\n\n",4);
  99.         Write(ixWindow,whoCalled[1].wa_Name,strlen(whoCalled[1].wa_Name));
  100.         Write(ixWindow," not found.",11);
  101. }
  102. earlyEnd:
  103.     Delay(250);
  104.     Close(ixWindow);
  105.     }         
  106. }
  107.  
  108.